package ac.neec.mio.ui.fragment;

import ac.neec.mio.R;
import ac.neec.mio.record.search.CallbackListener;
import ac.neec.mio.record.search.SearchCalenderDialog;
import ac.neec.mio.record.search.SearchSlidingDrawer;
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;

public class RecordSearchFragment extends Fragment implements CallbackListener{


	public static final String START_CALENDER = "開始日";
	public static final String END_CALENDER = "終了日";

	private ImageButton startCalenderButton;
	private ImageButton endCalenderButton;
	private SearchSlidingDrawer searchSlidingDrawer;
	private SearchCalenderDialog startCalenderDialog;
	private SearchCalenderDialog endCalenderDialog;
	private TextView startDate;
	private TextView endDate;
	private Activity activity;


	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		this.activity = activity;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_record_search, container, false);
		initFindViews(view);
		setLintener();
		return view;
	}

	private void initFindViews(View view){
		searchSlidingDrawer = (SearchSlidingDrawer) view.findViewById(R.id.drawer);
		startCalenderButton = (ImageButton) view.findViewById(R.id.btn_start_calender);
		endCalenderButton = (ImageButton) view.findViewById(R.id.btn_end_calender);
		startDate = (TextView) view.findViewById(R.id.text_start_date);
		endDate = (TextView) view.findViewById(R.id.text_end_date);
		searchSlidingDrawer.setDateText(startDate, endDate);

	}
	private void setLintener() {
		startCalenderButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				startCalenderDialog = createDialog(SearchCalenderDialog.START_DATE_SETTING);
				startCalenderDialog.show(getFragmentManager(), START_CALENDER);
			}
		});
		endCalenderButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				endCalenderDialog = createDialog(SearchCalenderDialog.END_DATE_SETTING);
				endCalenderDialog.show(getFragmentManager(), END_CALENDER);
			}
		});
	}
	private SearchCalenderDialog createDialog(int condition) {
		return new SearchCalenderDialog(
				condition,  this,
				searchSlidingDrawer.getnYear(), searchSlidingDrawer.getnMonth(),
				searchSlidingDrawer.getnDay());
	}

	@Override
	public void startDateUpdate(int y, int m, int d) {
		// TODO 自動生成されたメソッド・スタブ
		searchSlidingDrawer.setStartDate(y, m, d);


	}

	@Override
	public void endDateUpdate(int y, int m, int d) {
		// TODO 自動生成されたメソッド・スタブ
		searchSlidingDrawer.setEndDate(y, m, d);


	}


	@Override
	public void select(String text) {
		// TODO 自動生成されたメソッド・スタブ

	}


}
